/*
 * @(#)MaintWorkflowQueryRecordAction.java
 *
 * Copyright (c) 2004 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of DCIVision
 * Ltd ("Confidential Information").  You shall not disclose such Confidential
 * Information and shall use it only in accordance with the terms of the license
 * agreement you entered into with DCIVision Ltd.
 */
package com.dcivision.workflow.web;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.dcivision.framework.ApplicationException;
import com.dcivision.framework.GlobalConstant;
import com.dcivision.framework.PermissionManager;
import com.dcivision.framework.SessionContainer;
import com.dcivision.framework.SystemFunctionConstant;
import com.dcivision.framework.Utility;
import com.dcivision.framework.web.AbstractActionForm;
import com.dcivision.framework.web.AbstractListAction;
import com.dcivision.workflow.bean.WorkflowQueryRecord;
import com.dcivision.workflow.core.WorkflowOperationManager;
import com.dcivision.workflow.dao.WorkflowQueryRecordDAObject;

/**
  MaintWorkflowRecordAction.java

  This class is for maint wprkflow record.

    @author          Angus Shiu
    @company         DCIVision Limited
    @creation date   29/07/2003
    @version         $Revision: 1.4 $
*/
public class MaintWorkflowQueryRecordAction extends AbstractListAction {

  public static final String REVISION = "$Revision: 1.4 $";

  public static final String VAR_ACCESSIBLE_GROUP_LIST = "accessibleGroupList";
  /** Creates a new instance of MaintWorkflowRecordAction */
  public MaintWorkflowQueryRecordAction() {
    super();
    this.setListName("workflowQueryRecordList");
    this.setListFunctionName("getListByUserRecordIDOrQueryType");
  }

  /** getFunctionCode
   *
   * Abstract function which sub-class should implement to return the corresponding
   * function code.
   *
   * @return   The function code
   */
  public String getFunctionCode() {
    return(SystemFunctionConstant.WORKFLOW_MONITOR);
  }

  /** getMajorDAOClassName
   *
   * Abstract function which sub-class should implement to return the corresponding
   * major DAO class name used in this class.
   *
   * @return   The DAO class name
   */
  public String getMajorDAOClassName() {
    return("com.dcivision.workflow.dao.WorkflowQueryRecordDAObject");
  }

  public void clearUniqueFields(ActionMapping mapping, AbstractActionForm form, HttpServletRequest request, HttpServletResponse response) throws ApplicationException {
    MaintWorkflowRecordForm workflowRecordForm = (MaintWorkflowRecordForm) form;
    workflowRecordForm.setID(null);
    workflowRecordForm.setWorkflowVersion(null);
    workflowRecordForm.setStatus(GlobalConstant.RECORD_PENDING);
    workflowRecordForm.setDescription(null);
  }

  public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws ServletException {
    ActionForward retValue;
    SessionContainer sessionContainer = (SessionContainer) request.getSession().getAttribute(GlobalConstant.SESSION_CONTAINER_KEY);
    PermissionManager permissionManager = sessionContainer.getPermissionManager();
    WorkflowOperationManager wfOperationManager = new WorkflowOperationManager(sessionContainer,this.getConnection(request));
    WorkflowQueryRecordDAObject workflowQueryRecordDAO = new WorkflowQueryRecordDAObject(sessionContainer,this.getConnection(request));
    MaintWorkflowQueryRecordForm maintForm = (MaintWorkflowQueryRecordForm) form;

    String opMode = (maintForm!=null) ? maintForm.getOpMode() : request.getParameter("opMode");    //maintForm.getOpMode();
    String navMode = (maintForm!=null) ? maintForm.getNavMode() : request.getParameter("navMode"); //maintForm.getNavMode();
    String operationType = request.getParameter("operationType");

    //check whether the request come form applet
    String fromType = request.getParameter("fromType");
    log.debug( ((maintForm!=null) ? maintForm.getClass().getName() : "")+", OP Mode:"+opMode+", Nav Mode:"+navMode);
    maintForm.setUserRecordID(this.getSessionContainer(request).getUserRecordID().toString());
    // Set the function code for current action.
    ActionForward forward = this.retrieveFunctionCode(request, response, mapping);  if (forward!=null) {return forward;}

    if (WorkflowQueryRecord.RETURN_FORM_LIST_QUERY_RECORD.equals(fromType)){//if request come from applet,sendRedirect to applet
      List workflowQueryRecordList = new ArrayList();
      workflowQueryRecordList = workflowQueryRecordDAO.getListByUserRecordIDOrQueryType(maintForm);
      request.setAttribute("workflowQueryRecordList",workflowQueryRecordList);
      return mapping.findForward(WorkflowQueryRecord.RETURN_FORM_LIST_QUERY_RECORD);
    }
    // delete selected Query record
    else if (!Utility.isEmpty(opMode) && GlobalConstant.OP_MODE_DELETE.equals(opMode)){

    } else {
      return super.execute(mapping,form,request,response);
    }
  return null;
  }



/*
  public void deleteListData(ActionMapping mapping, AbstractSearchForm form, HttpServletRequest request, HttpServletResponse response) throws ApplicationException {
    WorkflowQueryRecordDAObject workflowQueryRecordDAO = new WorkflowQueryRecordDAObject(this.getSessionContainer(request),this.getConnection(request));
    MaintWorkflowQueryRecordForm maintWorkflowQueryRecordForm = (MaintWorkflowQueryRecordForm)form;
    workflowQueryRecordDAO.deleteList(maintWorkflowQueryRecordForm.getBasicSelectedID());
  }
*/




}
